package com.dongdongshop.service.impl;

import com.dongdongshop.mapper.TbUserMapper;
import com.dongdongshop.pojo.TbUser;
import com.dongdongshop.pojo.TbUserExample;
import com.dongdongshop.service.UserService;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@DubboService
@Service
public class UserServiceImpl implements UserService {
    @Autowired
    private TbUserMapper tbUserMapper;

    @Override
    public TbUser getUserByPname(String username) {
        TbUserExample example = new TbUserExample();
        TbUserExample.Criteria criteria = example.createCriteria();
        criteria.andUsernameEqualTo(username);
        List<TbUser> tbUsers = tbUserMapper.selectByExample(example);
        return tbUsers.size()>0 ? tbUsers.get(0):null;
//        return Optional.ofNullable(tbUsers).map(tbUsers1 -> tbUsers1.get(0)).orElse(null);
    }

    @Override
    public void insertSeller(TbUser user) {
        user.setCreated(new Date());
        user.setUpdated(new Date());
        tbUserMapper.insertSelective(user);
    }
}
